﻿using System.Web.Mvc;
using NUnit.Framework;
using TestDrivenDevelopment.Controllers;
using TestDrivenDevelopment.Models;

namespace TestDrivenDevelopment.Fixture.Controllers
{
    public class HomeControllerSpec
    {
        [Test]
        public void Index_Always_LoadTasksFromDatabase()
        {
            //Arrange
            StubTaskRepository repository = new StubTaskRepository();
            
            //Act
            HomeController controller = new HomeController(repository);
            ViewResult result = controller.Index();

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(StubTaskRepository.Tasks, result.ViewData.Model);
        }

        private class StubTaskRepository : ITaskRepository
        {
            public static string[] Tasks = new[] { "AAA", "BBB" };

            public string[] GetTasks()
            {
                return Tasks;
            }
        }
    }
}
